
<template>
<!-- 搜索商品，模糊搜索 -->
    <div class="goodsearch">
        <el-input v-model="goodsearch" placeholder="" v-on:input="awaysknow"></el-input>
        <ul class="goodListUl">
            <li @click="liClick(item)" v-for="(item,i) in searchItemGood" :key="i" :item="item">
                <span v-if="input_url == 'operate_v3/ritems/search'">{{item.item_name}}</span>
                <span v-else-if="input_url == 'operate/coupon/search'">{{item.name}}</span>
                <span v-else-if="input_url == 'operate/contract/search'">{{item.title}}</span>
                <span v-else>{{item.product_name}}</span>                
            </li>
        </ul>
    </div>
</template>
<style lang="scss" scoped>
.goodsearch{
    width:100%;
    position: relative;
    min-height: 40px;
    z-index: 10;
    // overflow: auto;
    .goodListUl{
        width:100%;
        position: relative;
        left: 0;
        // top:40px;
        top:0;
        box-shadow: 0 0 10px rgba(0,0,0,0.5);
        background: #fff;
        border-radius: 5px;
        li{
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            padding:0 10px;
            width: 100%;
            overflow: hidden;
            box-sizing: border-box;
        }
        li:hover{
            background: #f4f4f4;
        }
    }
}
</style>
<script>
import { abc } from "../../../js/abc.js"; 
import {potUrl} from '../../../js/config_url.js';
    export default {
        props:['input_url','default_txt','id','i'],

        data(){
            return {
                goodsearch:this.default_txt,
                searchItemGood:[]
            }
        },
        watch:{
            default_txt(n,o){
                this.goodsearch = n
            }
        },
        methods:{
            liClick(tem){
                console.log(tem,this.input_url)
                if(this.id){
                    tem.tritemindex = this.id
                } 
                if(this.i){
                    //vip充值挡位设置中需要得参数，largess中的索引值
                    tem.i = this.i
                }               
                this.$emit('getsearchItemGood',tem)  
                this.searchItemGood = [];
                if(tem.product_name){
                    this.goodsearch = tem.product_name
                }else if(tem.item_name){
                    this.goodsearch = tem.item_name
                }else if(this.input_url == 'operate/contract/search'){
                    this.goodsearch = tem.title
                }else{
                    this.goodsearch = tem.name
                }
                
            },
            awaysknow(e){
                var that = this;
                
                abc.get(that,that.input_url,{keywords:e,keyword:e},function(res){
                    that.searchItemGood = res.data;

                })

            }
        }
    }
</script>